package com.yupi.project.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.project.common.BaseResponse;
import com.yupi.project.common.ErrorCode;
import com.yupi.project.common.ResultUtils;
import com.yupi.project.exception.BusinessException;
import com.yupi.project.model.dto.student.VideoDto;
import com.yupi.project.model.entity.User;
import com.yupi.project.service.UserService;
import com.yupi.project.mapper.UserMapper;
import com.yupi.project.utils.FileUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 86189
 * @description 针对表【tb_user】的数据库操作Service实现
 * @createDate 2023-01-12 14:48:51
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {

    @Override
    public BaseResponse addVideo(VideoDto videoDto, MultipartFile file, MultipartFile image) {
        if (videoDto == null || file == null || image == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        User user = new User();
        //进行对象属性的转换 记住的是一定要是属性转成对的才行
        BeanUtils.copyProperties(videoDto, user);
//        QueryWrapper<User> wrapper = new QueryWrapper<>();
//        wrapper.eq("phone", user.getPhone());
        //参数不为null 我们要进行存储我们的数据
        String fileName = FileUtils.upload(file);
        user.setFile(fileName);
        String imageName = FileUtils.upload(image);
        user.setImage(imageName);
        boolean isSuccess = this.save(user);
        return ResultUtils.success(isSuccess);
    }
}




